<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script type="module">
            import axios from './Query.js'
            axios.get('hd.php', {
                success(goods) {
                    //获取最贵的商品
                    let item = goods.sort(order('price', 'desc'))[0]
                    console.log(item)
                    //获取评论
                    axios.get(`comment.php?id=${item.id}`, {
                        type: 'json',
                        success(comments) {
                            console.log(comments)
                        },
                    })
                },
            })
            //处理排序
            function order(field, type) {
                return (a, b) => {
                    switch (type) {
                        case 'asc':
                            return a[field] - b[field]
                            break
                        case 'desc':
                            return b[field] - a[field]
                    }
                }
            }
        </script>
    </body>
</html>
